#pragma once

#include <iostream>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/epoll.h>

#define BV(x) (1 << x)

#define FDEVENT_IN     BV(0)
#define FDEVENT_PRI    BV(1)
#define FDEVENT_OUT    BV(2)
#define FDEVENT_ERR    BV(3)
#define FDEVENT_HUP    BV(4)
#define FDEVENT_NVAL   BV(5)

class FdEvent {
	public:
	//FdEvent(){}
        //struct server *srv;
        
        //fdnode **fdarray;
        size_t maxfds;
        size_t highfd;
        
        virtual bool init()=0;
        virtual int reset()=0;
        virtual void free()=0;
        virtual int event_set( int fde_ndx, int fd, int events)=0;
        virtual int event_del( int fde_ndx, int fd)=0;
        virtual int event_get_revent( size_t ndx)=0;
        virtual int event_get_fd(size_t ndx)=0;
        virtual int event_next_fdndx( int ndx)=0;
        virtual int poll( int timeout_ms)=0;
        virtual int fcntl_set(int fd)=0;
};


class EpollEvent:public FdEvent{
    public:
	EpollEvent(size_t maxfds);
        int epoll_fd;
        struct epoll_event* epoll_events;  //array
        bool assign(int listen_fd,int FDEVENTS);
        bool init();
        bool init(int maxfds);
        int reset();
        void free();
        int event_set( int fde_ndx, int fd, int events);
        int event_del(int fde_ndx, int fd);
        int event_get_revent( size_t ndx);
        int event_get_fd( size_t ndx);
        int event_next_fdndx( int ndx);
        int poll( int timeout_ms);
        int fcntl_set( int fd);

};
